package com.cmc.cloud.cmclink.doc.controller.admin;

import cn.hutool.core.bean.BeanUtil;
import com.cmc.cloud.cmclink.doc.api.document.rep.BookingRequestConfigRespDto;
import com.cmc.cloud.cmclink.doc.api.document.req.BookingRequestConfigReqDto;
import com.cmc.cloud.cmclink.doc.constants.UrlConstants;
import com.cmc.cloud.cmclink.doc.entity.BookingRequestConfigDO;
import com.cmc.cloud.cmclink.doc.service.BookingRequestConfigService;
import com.cmc.cloud.cmclink.doc.vo.bookingrequestconfigvo.BookingRequestConfigCreateReqVO;
import com.cmc.cloud.cmclink.doc.vo.bookingrequestconfigvo.BookingRequestConfigPageReqVO;
import com.cmc.cloud.cmclink.doc.vo.bookingrequestconfigvo.BookingRequestConfigRespVO;
import com.cmc.cloud.cmclink.doc.vo.bookingrequestconfigvo.BookingRequestConfigUpdateReqVO;
import com.cmes.framework.biz.advice.annotations.UseResponsePropertyAdvice;
import com.cmes.framework.common.pojo.CommonResult;
import com.cmes.framework.common.pojo.PageResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Collection;
import java.util.List;


/**
 * 装船要求用箱要求订舱要求选项配置前端接口Controller
 *
 * @author codegen
 */
@Tag(name = "管理后台 - 装船要求用箱要求订舱要求选项配置")
@RestController
@Validated
@RequestMapping(UrlConstants.APPLICATION_URL + "/requestConfig")
public class BookingRequestConfigController {

    @Resource
    private BookingRequestConfigService bookingRequestConfigService;

    @Operation(summary = "创建装船要求用箱要求订舱要求选项配置")
    @PostMapping("/create")
    @PreAuthorize("@ss.hasPermission('doc:bookRequestConfig:add')")
    public CommonResult<Void> createBookingRequestConfig(@Valid @RequestBody BookingRequestConfigCreateReqVO createReqVO) {
        bookingRequestConfigService.createBookingRequestConfig(createReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "更新装船要求用箱要求订舱要求选项配置")
    @PostMapping("/update")
    @PreAuthorize("@ss.hasPermission({'doc:bookRequestConfig:edit','doc:bookRequestConfig:enable'})")
    public CommonResult<Void> updateBookingRequestConfig(@Valid @RequestBody BookingRequestConfigUpdateReqVO updateReqVO) {
        bookingRequestConfigService.updateBookingRequestConfig(updateReqVO);
        return CommonResult.success();
    }

    @Operation(summary = "删除装船要求用箱要求订舱要求选项配置")
    @PostMapping("/delete/{id}")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('doc:bookRequestConfig:delete')")
    public CommonResult<Void> deleteBookingRequestConfig(@PathVariable("id") Long id) {
        bookingRequestConfigService.deleteBookingRequestConfig(id);
        return CommonResult.success();
    }

    @Operation(summary = "获得装船要求用箱要求订舱要求选项配置")
    @GetMapping("/getById/{id}")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<BookingRequestConfigRespVO> getBookingRequestConfig(@PathVariable("id") Long id) {
        BookingRequestConfigDO bookingRequestConfig = bookingRequestConfigService.getBookingRequestConfig(id);
        return CommonResult.success(BeanUtil.copyProperties(bookingRequestConfig, BookingRequestConfigRespVO.class));
    }

    @Operation(summary = "获得装船要求用箱要求订舱要求选项配置列表")
    @GetMapping("/listAll")
    @Parameter(name = "ids", description = "编号列表", required = true, example = "1024,2048")
    public CommonResult<List<BookingRequestConfigRespVO>> getBookingRequestConfigList(@RequestParam("ids") Collection<Long> ids) {
        List<BookingRequestConfigDO> list = bookingRequestConfigService.getBookingRequestConfigList(ids);
        return CommonResult.success(BeanUtil.copyToList(list, BookingRequestConfigRespVO.class));
    }

    @Operation(summary = "获得装船要求用箱要求订舱要求选项配置分页")
    @PostMapping("/getPage")
    @UseResponsePropertyAdvice
    @PreAuthorize("@ss.hasPermission('doc:bookRequestConfig:search')")
    public CommonResult<PageResult<BookingRequestConfigRespVO>> getBookingRequestConfigPage(@Valid @RequestBody BookingRequestConfigPageReqVO pageVO) {
        PageResult<BookingRequestConfigDO> pageResult = bookingRequestConfigService.getBookingRequestConfigPage(pageVO);
        List<BookingRequestConfigRespVO> results = BeanUtil.copyToList(pageResult.getList(), BookingRequestConfigRespVO.class);
        return CommonResult.success(new PageResult<>(results, pageResult.getTotal()));
    }

    @Operation(summary = "获得装船要求全量可用数据")
    @PostMapping("/getAllEnable")
    public CommonResult<List<BookingRequestConfigRespDto>> queryBookingRequestConfig(@RequestBody BookingRequestConfigReqDto bookingRequestConfigReqDto) {
        return CommonResult.success(bookingRequestConfigService.queryBookingRequestConfig(bookingRequestConfigReqDto));
    }
}
